// pages/my/my.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
  data: {
    avatarurl:defaultAvatarUrl,
    username:'',
    logined:false,
    h:0,
    storage:'1G',
    progress:10
  },
  onShow: function() {
    const self = this;
    wx.getSystemInfo({
      success: function(res) {
        self.setData({
          h:res.windowHeight
        })
      }
    });
    // 页面加载时获取用户信息
    let avatarurl = wx.getStorageSync('avatarurl')
    let username = wx.getStorageSync('username')
    this.setData({
      username: username||'登录',
      avatarurl:avatarurl||defaultAvatarUrl,
      logined:wx.getStorageSync('logined')
    });
  },
  warning(){
    let avatarurl = wx.getStorageSync('avatarurl')
    let username = wx.getStorageSync('username')
    if(avatarurl==""||username==""){
      wx.showToast({
        title: '请登录',
        icon: 'none'
      });
      return false;
    }
    return true;
  },
  login:function () {
    if(wx.getStorageSync('logined'))return;
    wx.navigateTo({
      url: '../login/login',
    })
  },
  start(){
    if(!this.warning())return;
    wx.showToast({
      title: '暂为开放，敬请期待',
      icon: 'none'
    });
  },
  share(){
    if(!this.warning())return;
    wx.showToast({
      title: '暂为开放，敬请期待',
      icon: 'none'
    });
  },
  recycle(){
    if(!this.warning())return;
  },
  download(){
    if(!this.warning())return;
    wx.showToast({
      title: '暂为开放，敬请期待',
      icon: 'none'
    });
  },
  setting(){
    if(!this.warning())return;
    wx.navigateTo({
      url: '../setting/setting',
    })
  },
  more(){
    if(!this.warning())return;
    wx.showToast({
      title: '暂为开放，敬请期待',
      icon: 'none'
    });
  },
  help(){
    if(!this.warning())return;
    wx.navigateTo({
      url: '../help/help',
    })
  }
});